package cn.doitedu.operate

import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.{DataFrame, SparkSession}

/**
 * @Date 22.4.10
 * @Created by HANGGE
 * @Description
 */
object C04_DSL_Where {
  Logger.getLogger("org").setLevel(Level.ERROR)
  def main(args: Array[String]): Unit = {
    // 1 获取会话
    val session = SparkSession.builder()
      .appName(this.getClass.getSimpleName)
      .master("local[*]")
      .getOrCreate()
     // 导入SQL函数和隐式
    import session.implicits._
    // 具有丰富的操作字段的函数
    import org.apache.spark.sql.functions._
    // 2 加载数据   创建DataFrame
    val df: DataFrame = session.read.option("header" , true).option("inferSchema",true).csv("file:///D://code/doit30_spark_sql/data/csv/Teacher2.csv")
    df.show()
    println("======================================年龄大于30")
    df.where("age > 30").show()
    println("======================================年龄大于30 并且薪资在2w+ ")
    df.where("age > 30 and  sal > 20000").show()
    println("======================================年龄大于30 并且薪资在2w+ ")
    df.where('age > 30 and $"sal" > 20000).select("id" , "name" , "age" , "sal").show()

  }

}
